<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>

<body>
  <script>
    var contains = function (nums, k, t) {
      // 解法一：快慢指针
      let s = 0, f = 1
      // 循环数组
      while (f <= nums.length) {
        // 快指针和慢指针的差要小于等于k，当f的值和数组长度一样的时候还没返回，证明慢指针对应的值和快指针扫过的值都没有符合条件的值，那就要移动慢指针，重置快指针，继续寻找
        if (f - s > k || f === nums.length) {
          s++
          f = s + 1
          continue
        }
        // 计算快慢指针对应值的绝对值是否小于等于t
        if (Math.abs(nums[s] - nums[f]) <= t) return true
        // 大于t， f++，继续完后寻找
        else f++
      }
      return false
    }
    console.log(contains(nums = [1, 2, 3, 1], indexDiff = 3, valueDiff = 0))
  </script>
</body>

</html>